package com.ruoyi.production.service.impl.pesticide;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.domain.OrderAllocation;
import com.ruoyi.order.mapper.OrderAllocationMapper;
import com.ruoyi.production.domain.pesticide.PesticideApply;
import com.ruoyi.production.mapper.pesticide.PesticideApplyMapper;
import com.ruoyi.production.service.pesticide.IPesticideApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 农药申请Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@Service
public class PesticideApplyServiceImpl implements IPesticideApplyService
{
    @Autowired
    private PesticideApplyMapper pesticideApplyMapper;
    @Autowired
    private OrderAllocationMapper orderAllocationMapper;

    /**
     * 查询农药申请
     *
     * @param pesticideApplyId 农药申请ID
     * @return 农药申请
     */
    @Override
    public PesticideApply selectPesticideApplyById(Long pesticideApplyId)
    {
        return pesticideApplyMapper.selectPesticideApplyById(pesticideApplyId);
    }

    /**
     * 查询农药申请列表
     *
     * @param pesticideApply 农药申请
     * @return 农药申请
     */
    @Override
    public List<PesticideApply> selectPesticideApplyList(PesticideApply pesticideApply)
    {
        return pesticideApplyMapper.selectPesticideApplyList(pesticideApply);
    }

    /**
     * 新增农药申请
     *
     * @param pesticideApply 农药申请
     * @return 结果
     */
    @Override
    public int insertPesticideApply(PesticideApply pesticideApply)
    {
        Long orderAllocationId = pesticideApply.getOrderAllocationId();
        OrderAllocation orderAllocation = orderAllocationMapper.selectOrderAllocationById(orderAllocationId);
        pesticideApply.setOrderId(orderAllocation.getOrderId());














        pesticideApply.setCreateTime(DateUtils.getNowDate());



        return pesticideApplyMapper.insertPesticideApply(pesticideApply);
    }

    /**
     * 修改农药申请
     *
     * @param pesticideApply 农药申请
     * @return 结果
     */
    @Override
    public int updatePesticideApply(PesticideApply pesticideApply)
    {
        pesticideApply.setUpdateTime(DateUtils.getNowDate());
        return pesticideApplyMapper.updatePesticideApply(pesticideApply);
    }

    /**
     * 批量删除农药申请
     *
     * @param pesticideApplyIds 需要删除的农药申请ID
     * @return 结果
     */
    @Override
    public int deletePesticideApplyByIds(Long[] pesticideApplyIds)
    {
        return pesticideApplyMapper.deletePesticideApplyByIds(pesticideApplyIds);
    }

    /**
     * 删除农药申请信息
     *
     * @param pesticideApplyId 农药申请ID
     * @return 结果
     */
    @Override
    public int deletePesticideApplyById(Long pesticideApplyId)
    {
        return pesticideApplyMapper.deletePesticideApplyById(pesticideApplyId);
    }
}
